Imports System.Xml

Namespace DotNetNuke.UI.WebControls

	Public MustInherit Class XmlCollectionBase : Implements ICollection, IList, IEnumerable
#Region "Member Variables"
		Private m_arr As ArrayList	   'THIS IS NOT USED BUT IS NECESSARY FOR BACKWARDS COMPATIBILITY!!!! DO NOT REMOVE!!!!
		Private m_objXMLNode As XmlNode
		Private m_objXMLDoc As XmlDocument
		'Private m_objNode As DNNNode
#End Region

#Region "Constructors"
		Protected Sub New()

		End Sub

		''' -----------------------------------------------------------------------------
		''' <summary>
		''' Constructor to call when creating a Root Node
		''' </summary>
		''' <param name="strNamespace">Namespace of node hierarchy</param>
		''' <remarks>
		''' </remarks>
		''' <history>
		''' 	[Jon Henning]	12/22/2004	Created
		''' </history>
		''' -----------------------------------------------------------------------------
		Public Sub New(ByVal strNamespace As String)
			InnerXMLDoc = New System.Xml.XmlDocument
			InnerXMLNode = InnerXMLDoc.CreateNode(XmlNodeType.Element, "root", "")

			Dim objAttr As System.Xml.XmlAttribute = InnerXMLDoc.CreateAttribute("id")
			objAttr.Value = strNamespace
			InnerXMLNode.Attributes.Append(objAttr)

			InnerXMLDoc.AppendChild(InnerXMLNode)
		End Sub

		''' -----------------------------------------------------------------------------
		''' <summary>
		''' Loads node collection based off of XML string
		''' </summary>
		''' <param name="strXML">XML string</param>
		''' <param name="strXSLFile">XSL FileName.  Leave empty if no transform needed</param>
		''' <remarks>
		''' </remarks>
		''' <history>
		''' 	[Jon Henning]	12/22/2004	Created
		''' </history>
		''' -----------------------------------------------------------------------------
		Public Sub New(ByVal strXML As String, ByVal strXSLFile As String)
			InnerXMLDoc = New System.Xml.XmlDocument
			If Len(strXSLFile) > 0 Then
				'InnerXMLDoc.LoadXml(DoTransform(strXML, strXSLFile))
			Else
				InnerXMLDoc.LoadXml(strXML)
			End If
			InnerXMLNode = InnerXMLDoc.SelectSingleNode("//root")
			'm_objNode = New DNNNode(InnerXMLNode)
		End Sub

		''' -----------------------------------------------------------------------------
		''' <summary>
		''' Constructor for all nodes that are not the root.  
		''' </summary>
		''' <param name="objXmlNode">Node whose children will be exposed by this class</param>
		''' <remarks>
		''' </remarks>
		''' <history>
		''' 	[Jon Henning]	12/22/2004	Created
		''' </history>
		''' -----------------------------------------------------------------------------
		Public Sub New(ByVal objXmlNode As XmlNode)
			InnerXMLNode = objXmlNode
			InnerXMLDoc = InnerXMLNode.OwnerDocument
			'm_objNode = New DNNNode(InnerXMLNode)
		End Sub


#Region "TreeView Backwards Compatibility"
		Private m_objTree As DotNetNuke.UI.WebControls.DnnTree
		'In order to maintain backwards compatibility with the tree from versions before 3.2 we need to allow the 
		'baseclass to return the treenodeenumerator, thus the need to pass the tree to the new base collection class
		'Yes, this is a hack!
		Protected Sub New(ByVal objTreeControl As DotNetNuke.UI.WebControls.DnnTree)
			m_objTree = objTreeControl
		End Sub

		Public Sub New(ByVal objXmlNode As XmlNode, ByVal objTreeControl As DotNetNuke.UI.WebControls.DnnTree)
			m_objTree = objTreeControl
			InnerXMLNode = objXmlNode
			InnerXMLDoc = InnerXMLNode.OwnerDocument
		End Sub

		Public Sub New(ByVal strNamespace As String, ByVal objTreeControl As DotNetNuke.UI.WebControls.DnnTree)
			m_objTree = objTreeControl
			InnerXMLDoc = New System.Xml.XmlDocument
			InnerXMLNode = InnerXMLDoc.CreateNode(XmlNodeType.Element, "root", "")

			Dim objAttr As System.Xml.XmlAttribute = InnerXMLDoc.CreateAttribute("id")
			objAttr.Value = strNamespace
			InnerXMLNode.Attributes.Append(objAttr)

			InnerXMLDoc.AppendChild(InnerXMLNode)
		End Sub
#End Region

#End Region

		Public Sub Clear() Implements System.Collections.IList.Clear
			Dim i As Integer
			For i = Me.InnerXMLNode.ChildNodes.Count - 1 To 0 Step -1
				Me.InnerXMLNode.RemoveChild(Me.InnerXMLNode.ChildNodes(i))
			Next
		End Sub
		Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
			'In order to maintain backwards compatibility with the tree from versions before 3.2 we need to allow the 
			'baseclass to return the treenodeenumerator, thus the need to pass the tree to the new base collection class
			'Yes, this is a hack!
			If m_objTree Is Nothing Then
				Return m_objXMLNode.ChildNodes.GetEnumerator()
			Else
				Return New TreeNodeEnumerator(m_objXMLNode, m_objTree)
			End If
		End Function

		Public Sub RemoveAt(ByVal index As Integer) Implements System.Collections.IList.RemoveAt
			Me.InnerXMLNode.RemoveChild(Me.InnerXMLNode.ChildNodes(index))
		End Sub

#Region "Unused Interface Implementations"
		Private Sub CopyTo(ByVal array As System.Array, ByVal index As Integer) Implements System.Collections.ICollection.CopyTo
		End Sub
		Private ReadOnly Property IsSynchronized() As Boolean Implements System.Collections.ICollection.IsSynchronized
			Get
			End Get
		End Property
		Private ReadOnly Property SyncRoot() As Object Implements System.Collections.ICollection.SyncRoot
			Get
			End Get
		End Property
		Private Function Add(ByVal value As Object) As Integer Implements System.Collections.IList.Add
		End Function
		Private Function Contains(ByVal value As Object) As Boolean Implements System.Collections.IList.Contains
		End Function
		Private ReadOnly Property IsFixedSize() As Boolean Implements System.Collections.IList.IsFixedSize
			Get
			End Get
		End Property
		Private ReadOnly Property IsReadOnly() As Boolean Implements System.Collections.IList.IsReadOnly
			Get
			End Get
		End Property
		Private Property Item(ByVal index As Integer) As Object Implements System.Collections.IList.Item
			Get
			End Get
			Set(ByVal Value As Object)
			End Set
		End Property
		Private Function IndexOf(ByVal value As Object) As Integer Implements System.Collections.IList.IndexOf
		End Function
		Private Sub Insert(ByVal index As Integer, ByVal value As Object) Implements System.Collections.IList.Insert
		End Sub
		Private Sub Remove(ByVal value As Object) Implements System.Collections.IList.Remove
		End Sub
#End Region

		Public ReadOnly Property Count() As Integer Implements System.Collections.ICollection.Count
			Get
				Return Me.InnerXMLNode.ChildNodes.Count
			End Get
		End Property

		'These are not necessary, but were in original CollectionBase class so keeping them
		Protected ReadOnly Property InnerList() As ArrayList
			Get
				Return Nothing
			End Get
		End Property
		'These are not necessary, but were in original CollectionBase class so keeping them
		Protected ReadOnly Property List() As IList
			Get
				Return Nothing
			End Get
		End Property

		Protected Property InnerXMLNode() As Xml.XmlNode
			Get
				Return m_objXMLNode
			End Get
			Set(ByVal Value As Xml.XmlNode)
				m_objXMLNode = Value
			End Set
		End Property

		Protected Property InnerXMLDoc() As Xml.XmlDocument
			Get
				Return m_objXMLDoc
			End Get
			Set(ByVal Value As Xml.XmlDocument)
				m_objXMLDoc = Value
			End Set
		End Property
	End Class

End Namespace
